package org.acmclass.fatworm.test.plaintext;

import java.util.Date;

import org.acmclass.fatworm.test.FatTestException;

public class Log {

	private FatFileWriter fileWriter;

	public Log(String filename) throws FatTestException {
		fileWriter = new FatFileWriter(filename, true);
	}

	private void writeLog(String message) {
		String msg = "[".concat(new Date().toString()).concat("] ").concat(
				message);
		fileWriter.writeLine(msg);
		System.out.println(msg);
	}

	public synchronized void log(String prefix, String message) {
		String[] lines = message.split("\n");
		for (String line : lines) {
			writeLog(prefix.concat(line));
		}
	}

	public void close() {
		if (fileWriter != null) {
			fileWriter.close();
		}
	}
}
